let vm = new Vue({
    el:'#app',  //选中整个main
    data:{
        user:{},//初始化对象     vue建议声明对象同时进行初始化，避免undefinded
        userFocusCount:''            //用户关注数
    },
    methods:{
        //获取关注的数量
        selectFavorites:function () {
            axios.get(`user/selectFavorites/${this.user.id}`).then(rs=>{
                if (rs.data.success){
                    this.userFocusCount=rs.data.obj;
                }
            }).catch(e=>{
                layer.msg(e.message);
            });
        },
        //修改个人信息
        update:function () {
            let checked = $("#checkboxCustom")[0].checked;
            // console.dir(checked)
            //是否私密
            this.user.isSecret=checked?'1':'0';
            axios.put(`user/update`,this.user).then(rs=>{
                if (rs.data.success){
                    user=rs.data.obj;
                    this.user=user;
                    sessionStorage.setItem('user',JSON.stringify(user));
                    location.href="html/home.html";
                    layer.msg(rs.data.msg);
                }
            }).catch(e=>{
                layer.msg(e.message);
            });
        },
        //图片上传
        uploadImg:function (e) {
            // let self = this;
            console.dir(e.target.files[0])
            let file = e.target.files[0];
            /* eslint-disable no-undef */
            let param = new FormData();  // 创建form对象
            param.append('upfile', file);  // 通过append向form对象添加数据
            // param.append('chunk', '0'); // 添加form表单中其他数据
            // console.log(param.get('file')) // FormData私有类对象，访问不到，可以通过get判断值是否传进去
            let config = {
                headers: {'Content-Type': 'multipart/form-data'}
            }
            // 添加请求头
            axios.post(`img/upload/${this.user.id}`, param, config)
                .then(res => {
                    if (res.data.success) {
                        this.user.pic=res.data.obj;
                        sessionStorage.setItem("user",JSON.stringify(this.user));
                        layer.msg(res.data.msg);
                        location.href="/html/user_look.html";
                    }else {
                        layer.msg(res.data.msg);
                    }
                })
        }
    },
    created:function () {
        this.user = JSON.parse(sessionStorage.getItem("user"));
        this.selectFavorites();
    }
});